﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
namespace ThuVien
{
    public partial class frmTraCuuSach : DevComponents.DotNetBar.Office2007RibbonForm 
    {
        public frmTraCuuSach()
        {
            InitializeComponent();
        }
        SachBUS sa_BUS = new SachBUS();
        SachDTO sa_DTO = new SachDTO();

        private void frmTraCuuSach_Load(object sender, EventArgs e)
        {
            
          
        }

        private void labelX1_Click(object sender, EventArgs e)
        {

        }

        private void textBoxX8_TextChanged(object sender, EventArgs e)
        {
            if (IsNumber(txtDenNam.Text))
            {
                //int tu = Convert.ToInt32(txtTuNam.Text);
                //int den = Convert.ToInt32(txtdenNam.Text);

            }
            else
            {
                MessageBox.Show("Bạn Phải Nhập số");
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
           
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (IsNumber(txtTuNam.Text) && IsNumber(txtDenNam.Text))
            {
                sa_BUS.khoitao_KN();
                DataSet ds = new DataSet();
                ds = sa_BUS.TimTheo_NamXB(Convert.ToInt32(txtTuNam.Text), Convert.ToInt32(txtDenNam.Text));
                dataGridViewX1.DataSource = ds.Tables[0];
            }   
        }

        private void txtmasach_TextChanged(object sender, EventArgs e)
        {
            sa_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds = sa_BUS.TimKiem_SachTheoMa(txtmasach.Text);
            dataGridViewX1.DataSource = ds.Tables[0];
            
        }

        private void txtTenSach_TextChanged(object sender, EventArgs e)
        {
            sa_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds = sa_BUS.TimKiem_SachTheoMa(txtTenSach.Text.Trim());
            dataGridViewX1.DataSource = ds.Tables[0];

        }

        private void txtTacGia_TextChanged(object sender, EventArgs e)
        {
            sa_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds = sa_BUS.TimKiem_SachTheoMa(txtTacGia.Text);
            dataGridViewX1.DataSource = ds.Tables[0];
        }

        private void txtNhaXB_TextChanged(object sender, EventArgs e)
        {
            sa_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds = sa_BUS.TimKiem_SachTheoMa(txtNhaXB.Text);
            dataGridViewX1.DataSource = ds.Tables[0];
        }

        private void txtGiaTu_TextChanged(object sender, EventArgs e)
        {

        }
        public bool IsNumber(string pText)
        {
            Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
            return regex.IsMatch(pText);
        }
        private void txtTuNam_TextChanged(object sender, EventArgs e)
        {
            if (IsNumber(txtTuNam.Text))
            {
                //int tu = Convert.ToInt32(txtTuNam.Text);
                //int den = Convert.ToInt32(txtdenNam.Text);

            }
            else
            {
                MessageBox.Show("Bạn Phải Nhập số");
            }
        }

        private void cbxMaSach_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxMaSach.Checked == false)
            {
                txtmasach.Enabled = true;
            }
            else
            {
                txtmasach.Enabled = false;
                txtmasach.Clear();
                
            }

        }

        private void cbxTenSach_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxTenSach.Checked == false )
            {
                txtTenSach.Enabled = true;

            }
            else
            {
                txtTenSach.Enabled = false;
                txtTenSach.Clear();
                
            }
        }

        private void cbxTacGia_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxTacGia.Checked == false)
            {
                txtTacGia.Enabled = true;
            }
            else
            {
                txtTacGia.Enabled = false;
                txtTacGia.Clear();
                
            
            
            }
        }

        private void cbxNhaXB_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxNamXB.Checked == false)
            {
                txtNhaXB.Enabled = true;
                
            }
            else
            {
                txtNhaXB.Enabled = false;
                txtNhaXB.Clear();
                
            }
        }

        private void cbxTriGia_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxTriGia.Checked == false)
            {
                txtGiaTu.Enabled = true;
                txtDenGia.Enabled = true;

            }
            else
            {
                txtGiaTu.Enabled = false;
                txtGiaTu.Clear();
                txtDenGia.Enabled = false;
                txtDenGia.Clear();
                
            }

        }

        private void cbxNamXB_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxNamXB.Checked == false)
            {
                txtTuNam.Enabled = true;
                txtDenNam.Enabled = true;

            }
            else
            {
                txtTuNam.Enabled = false;
                txtTuNam.Clear();
                txtDenNam.Enabled = false;
                txtDenNam.Clear();
                
            }
        }
    }
}
